﻿@model ESN.Models.CustomProfile

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var fPermission = parseInt($("#WallPermission").val().charAt(0));
        var uPermission = parseInt($("#WallPermission").val().charAt(1));
        var gPermission = parseInt($("#WallPermission").val().charAt(2));
        if (fPermission > 2) {
            $("#frw").attr("checked", true);
            $("#fpw").attr("checked", true);
        } else if (fPermission == 2) {
            $("#fpw").attr("checked", true);
        } else if (fPermission == 1) {
            $("#frw").attr("checked", true);
        }

        if (uPermission > 2) {
            $("#urw").attr("checked", true);
            $("#upw").attr("checked", true);
        } else if (uPermission == 2) {
            $("#upw").attr("checked", true);
        } else if (uPermission == 1) {
            $("#urw").attr("checked", true);
        }

        if (gPermission == 1) {
            $("#grw").attr("checked", true);
        }

        $(".wallPermissionCheckbox").change(function () {
            var f = 0;
            var u = 0;
            var g = 0;

            if ($("#frw").is(":checked"))
                f = f + 1;
            if ($("#fpw").is(":checked"))
                f = f + 2;

            if ($("#urw").is(":checked"))
                u = u + 1;
            if ($("#upw").is(":checked"))
                u = u + 2;

            if ($("#grw").is(":checked"))
                g = g + 1;

            $("form").valid();
            $("#WallPermission").val(f.toString() + u.toString() + g.toString());
        });
        $("a#changeAvatar").click(function () {
            window.open('/Home/UpdateAvatar?name=@Model.UserName', null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
            return false;
        });
    });
</script>
<h2>@ViewBag.Des</h2>
<form action="/Home/UpdateProfile" method="post">
    @Html.ValidationSummary(true)
    <fieldset>

        @Html.HiddenFor(model => model.UserId)
        @Html.HiddenFor(model => model.UserName)

        <div class="editor-label">
            @ViewBag.isPrivate
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.isPrivate)
            @Html.ValidationMessageFor(model => model.isPrivate)
        </div>

        <div class="editor-label">
            @ViewBag.DisplayName
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DisplayName)
            @Html.ValidationMessageFor(model => model.DisplayName)
        </div>

        <div class="editor-label">
            @ViewBag.FirstName
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>

        <div class="editor-label">
            @ViewBag.Lastname
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>

        <div class="editor-label">
            @ViewBag.Location
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Location)
            @Html.ValidationMessageFor(model => model.Location)
        </div>

        <div class="editor-label">
            @ViewBag.Avatar
        </div>
        <div class="editor-field">
            <div><img id="avatar" src="@Model.Avatar" width="120" height="150" alt="*" /></div>
            <a id="changeAvatar">@ViewBag.ChangeAvatar</a>
            @Html.HiddenFor(model => model.Avatar)
            @Html.ValidationMessageFor(model => model.Avatar)
        </div>

        <div class="editor-label">
            @ViewBag.Gender
        </div>
        <div class="editor-field">
            @ViewBag.Woman @Html.RadioButtonFor(model => model.Gender, true)
            @ViewBag.Man @Html.RadioButtonFor(model => model.Gender, false)
            @Html.ValidationMessageFor(model => model.Gender)
        </div>

        <div class="editor-label">
            @ViewBag.WallPermission
        </div>
        <div class="editor-field">
            <table style="text-align:center;">
                <thead>
                    <tr>
                        <th></th>
                        <th>@ViewBag.Read</th>
                        <th>@ViewBag.Post</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>@ViewBag.Friend</td>
                        <td><input id="frw" type="checkbox" class="wallPermissionCheckbox" /></td>
                        <td><input id="fpw" type="checkbox" class="wallPermissionCheckbox" /></td>
                    </tr>
                    <tr>
                        <td>@ViewBag.User</td>
                        <td><input id="urw" type="checkbox" class="wallPermissionCheckbox" /></td>
                        <td><input id="upw" type="checkbox" class="wallPermissionCheckbox" /></td>
                    </tr>
                    <tr>
                        <td>@ViewBag.Guest</td>
                        <td><input id="grw" type="checkbox" class="wallPermissionCheckbox" /></td>
                        <td><input type="checkbox" disabled="disabled" /></td>
                    </tr>
                </tbody>
            </table>
            @Html.HiddenFor(model => model.WallPermission)
            @Html.ValidationMessageFor(model => model.WallPermission)
        </div>

        <p>
            <input type="submit" value="@ViewBag.Save" />
        </p>
    </fieldset>
</form>